package admission.ecnu.service;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.Map;

import org.joda.time.DateTime;
import org.json.JSONArray;
import org.json.JSONObject;

import com.ecnu.sei.app.Scheduler;
import com.ecnu.sei.app.resources.Time;

import admission.ecnu.dao.classInfoDao;
import admission.ecnu.dao.teacherInfoDao;
import admission.ecnu.interfaces.IRnsService;
import admission.ecnu.mainservlet.RnsContext;
import admission.ecnu.object.DataManager;
import admission.ecnu.object.OClassInfo;
import admission.ecnu.object.OTeacherInfo;
import antlr.collections.List;
public class inputTime implements IRnsService {

	//private OClassInfo newClass = null;
	@Override
	public void executeService(RnsContext context) throws Exception {
		/*
		 * 验证用户key值
		 */
		
		System.out.print("time info:"+context.getJsonRequestObject());
		
		
		JSONObject obj = context.getJsonRequestObject();
		
		String compStartTime = obj.getString("compStartTime");
		compStartTime = new String(compStartTime.getBytes("iso-8859-1"),"utf-8"); 
		
		String compEndTime = obj.getString("compEndTime");
		compEndTime = new String(compEndTime.getBytes("iso-8859-1"),"utf-8"); 
		
		String elecStartTime = obj.getString("elecStartTime");
		elecStartTime = new String(elecStartTime.getBytes("iso-8859-1"),"utf-8"); 
		
		String elecEndTime = obj.getString("elecEndTime");
		elecEndTime = new String(elecEndTime.getBytes("iso-8859-1"),"utf-8"); 
		
		if(!DataManager.USER_ID.equals(obj.get("key"))){
			JSONObject jsonReturn = new JSONObject();
			jsonReturn.put("returnCode", DataManager.RETURN_WRONGKEY);
			context.setJsonResponseObject(jsonReturn);
			return;
		}
		
		
		String[]compStartTimeData = compStartTime.split("/");
		DateTime compStart = new DateTime(Integer.valueOf(compStartTimeData[0]),
								Integer.valueOf(compStartTimeData[1]), 
								Integer.valueOf(compStartTimeData[2]),0,0);
		
		
		String[]compEndTimeData = compEndTime.split("/");
		DateTime compEnd = new DateTime(Integer.valueOf(compEndTimeData[0]),
								Integer.valueOf(compEndTimeData[1]), 
								Integer.valueOf(compEndTimeData[2]),0,0);
		
		String[]elecStartTimeData = elecStartTime.split("/");
		DateTime elecStart = new DateTime(Integer.valueOf(elecStartTimeData[0]),
								Integer.valueOf(elecStartTimeData[1]), 
								Integer.valueOf(elecStartTimeData[2]),0,0);
		
		
		String[]elecEndTimeData = elecEndTime.split("/");
		DateTime elecEnd = new DateTime(Integer.valueOf(elecEndTimeData[0]),
								Integer.valueOf(elecEndTimeData[1]), 
								Integer.valueOf(elecEndTimeData[2]),0,0);
		
		DataManager.compStartTime = compStart.getMillis();
		DataManager.compEndTime = compEnd.getMillis();
		DataManager.elecStartTime = elecStart.getMillis();
		DataManager.elecEndTime = elecEnd.getMillis();
		//setExamTime(compStart.getMillis(), compEnd.getMillis(),elecStart.getMillis(),elecEnd.getMillis());
		
		
		
		
		JSONObject jsonReturn = new JSONObject();
		jsonReturn.put("returnCode", DataManager.RETURN_SUCCESSFUL);
		context.setJsonResponseObject(jsonReturn);
	}
}